require('../../../less/controls/table.less');
var React = require('react');
var TableHeader = require('./TableHeader');
var TableBody = require('./TableBody');

module.exports = React.createClass({
	displayName:'Table',
	getInitialState:function(){
		return {

		}
	},
	componentDidMount:function(){
		this._isInit = false;
	},
	__onHeaderCheckBoxChange: function (value){
		this.refs.tablebody.setAllChecked(value);
	},
	__onBodyCheckBoxChange: function (value, row, checkbox){
		//console.log(value, row.props, checkbox.props);
	},
	getCheckedItems: function (filter){
		return this.refs.tablebody.getCheckedItems(filter);
	},
	setData: function (data, argv){
		this.refs.tablebody.setData(data, argv);
	},
	addRow: function (data, argv){
		this.refs.tablebody.addRow(data);
	},
	render:function(){
		if(this.props.checkbox&&this.props.items[0].type!='checkbox'){
			this.props.items.unshift({
				type: 'checkbox',
				textAlign: 'center',
				width: this.props.checkbox
			});
		}
		return (
			<table className="c-table" >
				{this.props.showHeader && <TableHeader
					checkbox={this.props.checkbox}
					enableFilter={this.props.enableFilter}
					onCheckBoxChange={this.__onHeaderCheckBoxChange}
					items={this.props.items}/>}
				<TableBody
					ref="tablebody"
					columnRender={this.props.columnRender}
					checkbox={this.props.checkbox}
					items={this.props.items}
					onCheckBoxChange={this.__onBodyCheckBoxChange}
					data={this.props.data}/>
			</table>
		);
	}
});
